package demo;

import java.util.Arrays;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    //找出所有子集的异或总和再求和
    public int subsetXORSum(int[] nums) {
        return subsetXORSum(nums,0,0);
    }

    private int subsetXORSum(int[] nums,int xorSum,int index){

        if(index == nums.length-1){

            return xorSum + (xorSum^nums[index]);
        }
        int sumWithMe = subsetXORSum(nums,nums[index]^xorSum,index+1);
        int sumWithoutMe = subsetXORSum(nums,xorSum,index+1);

        return sumWithMe+sumWithoutMe;
    }

    //移动石子直到连续
    public int[] numMovesStones(int a, int b, int c) {
        int[] arr = new int[]{a, b, c};
        Arrays.sort(arr);
        int[] result = new int[2];

        if (arr[1] - arr[0] == 1 && arr[2] - arr[1] == 1) {
            result[0] = 0;
        } else if (arr[1] - arr[0] == 1 || arr[2] - arr[1] == 1 || arr[2] - arr[1] == 2 || arr[1] - arr[0] == 2) {
            result[0] = 1;
        } else {
            result[0] = 2;
        }
        result[1] = arr[2] - arr[0] - 2;
        return result;
    }
}
